package com.lqjava.tuxiaowang.tuxiaowang.customerapp.app.sdk.wechat.props;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.net.URLEncoder;

@Data
@Component
@ConfigurationProperties(prefix = "wx")
public class WchatProps {
	
	//微信 OAuth2.0登录接口地址
	public static final String OAUTH_BASE_URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=1#wechat_redirect";
	
	private String appId;
	private String appSecret;
	private String serverUri;
	private String redirectUri;
	private String accessTokenURL;
	
	private String uiPayPath;
	private String uiIndexPath;
	
	
	public String getRedirectUri(String params) {
		try {
			String encode = URLEncoder.encode(params != null ? this.redirectUri + params : this.redirectUri ,"utf-8");
			String format = String.format(WchatProps.OAUTH_BASE_URL, this.appId, encode);
			return format;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
